<?php

class User{

	var $db;

	public function __construct(){
		$this->db = new DBClass();
	}
	
	public function get_all_user(){
		
		$query = "Select * from user";

		$rows = $this->db->getRows($query);

		return $rows;	

	}


	public function addUser($data){
		
		$query ="INSERT INTO user SET username='".@$data['user_username']."',
		password='".md5(@$data['password'])."',
		foto_profil='".@$data['foto_profil']."',
		nama_lengkap='".@$data['nama_lengkap']."',
		gender='".@$data['gender']."',
		email='".@$data['email']."',
		access='".@$data['access']."'";

		$rows = $this->db->putRows($query);

		return $this->db->insertID();
		//header('Location: user.php');
	}

	public function editUser($data){
		
		$query ="UPDATE user SET username='".@$data['username']."',nama_lengkap='".@$data['nama_lengkap']."',foto_profil='".@$data['foto_profil']."',gender='".@$data['gender']."',email='".@$data['email']."',access='".@$data['access']."' WHERE id_user='".@$data['iduser']."'";

		$query = $this->db->putRows($query);
		
		return $query;
		//header('Location: user.php');
	}

	public function getUser($data){
		
		$query ="SELECT * FROM user WHERE id_user=".@$data;

		$rows = $this->db->getRows($query);
		return array_shift($rows);
	}

	public function deleteUser($id){
		
		$query ="DELETE FROM user WHERE id_user='".@$id."'";

		$rows = $this->db->getRows($query);

		header('Location: user.php');
	}

	public function insertImage($id, $imageName) {
		$query ="UPDATE user SET foto_profil='".@$imageName."' WHERE id_user='".$id."'";

		$rows = $this->db->putRows($query);

		return $rows;
	}

}